<?php

class ScoreManager_ScoreQueryController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $this->view->yearSemester = $this->getRequest()->getPost('yearSemester');
        $this->view->selectClass = $this->getRequest()->getPost('select-class');
        if ( $this->view->yearSemester and $this->view->selectClass) {
            $tempArr = explode("-",$this->view->yearSemester);
            $year = (int) $tempArr[0];
            $semester = (int)$tempArr[1];
            $tempArr = explode("-", $this->view->selectClass);
            $grade = (int)$tempArr[0];
            $examine = new Semester_Model_SemesterExamine();
            $examineSet = $examine->getExaminSet($year, $semester, $grade);
            // 考試設定
            $this->view->examineSet = $examineSet;
            $stage = (int)$this->getRequest()->getPost('stage');
            if ($stage) {
                $this->view->stage = $stage;
                  // 加計平時成績
                $this->view->plusCount = (int)$this->getRequest()->getParam('plusCount');
                // 加權計算
                $this->view->rateCount = (int)$this->getRequest()->getParam('rateCount');
                $this->view->rankPrint = (int)$this->getRequest()->getParam('rankPrint');
                $this->view->signPrint = (int)$this->getRequest()->getParam('signPrint');
            }

        }
    }
    /**
     * 成績列表
     * @return unknown_type
     */
    public function getScoreAction()
    {
        $this->getHelper('layout')->disableLayout();
        $classNum = $this->_getParam('classSn');
        $yearSemester = $this->_getParam('yearSemester');
        // 取出班級階段成績資料
        $statistics = new Score_Model_Statistics($classNum, $yearSemester);
        $stage = (int) $this->getRequest()->getParam('stage',0);
        if ($stage == 0)
        throw new Score_Model_Exception('Error stage id');
        // 加計平時成績
        $plusCount = (int)$this->getRequest()->getParam('plusCount');
        // 加權計算
        $rateCount = (int)$this->getRequest()->getParam('rateCount');

        $this->view->rateCount = $rateCount;
        //學生成績
        $studentScore = $statistics->getStudentScore($stage,$plusCount,$rateCount);
        if (!$studentScore) {
            echo ''; exit;
        }

        $this->view->studentScore = $studentScore;

        // 課程名稱
        $this->view->subject = $statistics->getSubject();

    }

    /**
     * 友善列印
     * @return unknown_type
     */
    public function printScoreAction()
    {
        $this->getHelper('layout')->disableLayout();
         $classNum = $this->_getParam('classSn');
        $yearSemester = $this->_getParam('yearSemester');
        // 取出班級階段成績資料
        $statistics = new Score_Model_Statistics($classNum, $yearSemester);
        $stage = (int) $this->getRequest()->getParam('stage',0);
        if ($stage == 0)
        throw new Score_Model_Exception('Error stage id');

        $this->view->className = $statistics->getClassName();
        // 階段
        $this->view->stage = $stage;
        // 加計平時成績
        $plusCount = (int)$this->getRequest()->getParam('plusCount');
        // 加權計算
        $rateCount = (int)$this->getRequest()->getParam('rateCount');
        // 列印簽章
        $this->view->signPrint = (int)$this->getRequest()->getParam('signPrint');
        // 列印名次
        $this->view->rankPrint = (int)$this->getRequest()->getParam('rankPrint');

        $this->view->plusCount = $plusCount;

        $this->view->rateCount = $rateCount;
        //學生成績
        $this->view->studentScore = $statistics->getStudentScore($stage,$plusCount,$rateCount);
        // 課程名稱
        $this->view->subject = $statistics->getSubject();
    }


}

